import os

# os.path.join(): 拼接路径
path = os.path.join("../resources", "file.txt")
print(path) # ../resources/file.txt

# os.path.abspath(): 获取绝对路径
abs_path = os.path.abspath("../resources/file.txt")
print(abs_path) # E:\project\python\python_learn\Python_learn_growth\src\resources\file.txt

# os.path.basename(): 获取文件名(包含文件扩展名)
file_name = os.path.basename("../resources/file.txt")
print(file_name)    # file.txt

# os.path.dirname(): 获取文件所在的目录
dir_name = os.path.dirname("../resources/file.txt")
print(dir_name) # ../resources

# os.path.exists(): 判断文件或目录是否存在
print(os.path.exists("../resources/file.txt"))  # True
print(os.path.exists("../resources"))   # True
print(os.path.exists("../resources/file1.txt")) # False
print(os.path.exists("../resources/"))  # True
print(os.path.exists("../resources1/")) # False

# os.path.splitext(): 获取文件扩展名
print(os.path.splitext("../resources/file.txt"))    # ('../resources/file', '.txt')
print(os.path.splitext("../resources")) # ('../resources', '')
print(os.path.splitext("../resources/"))    # ('../resources/', '')
print(os.path.splitext(os.path.basename("../resources/file.txt")))  # ('file', '.txt')

# os.path.isabs(): 判断路径是否为绝对路径
print(os.path.isabs("../resources/file.txt"))   # False
print(os.path.isabs(os.path.abspath("../resources/file.txt")))  # True

# os.path.isfile(): 判断路径是否为文件
print(os.path.isfile("../resources/file.txt"))  # True
print(os.path.isfile("../resources"))   #  False

# os.path.isdir(): 判断路径是否为目录
print(os.path.isdir("../resources/file.txt"))   # False
print(os.path.isdir("../resources"))    # True

# os.path.getsize(): 获取文件大小 字节数
print(os.path.getsize("../resources/file.txt")) # 21字节
# 如果这里是一个目录，那么返回的是目录的大小，一般是4096或者是8192
print(os.path.getsize("./"))    # 8192